package com.study.scala.function

import scala.annotation.tailrec

object FunctionTest {

  def main(args: Array[String]): Unit = {
    printArray("a", "b")
    printArray("a", "b", "c")
    println(factorial2(3))
  }

  def printArray(args: String*) {
    args.foreach(print(_));
  }

  def factorial1(n: Int): Long = {
    if (n <= 0) 1
    else n * factorial1(n - 1)
  }
  
  def factorial2(n:Int):Long = {
    @tailrec
    def factorial(main:Int,aggr:Int): Long ={
        if(main <= 0) aggr
        else factorial(main-1,main*aggr)
    }
    
   factorial(n,1)
}

}